package com.oracle.dao;

import com.oracle.dao.impl.CategoryDao;
import com.oracle.mapper.CategoryMapper;
import com.oracle.pojo.Category;
import com.oracle.pojo.CategoryExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CategoryDaoImpl implements CategoryDao {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void insertByCategory(Category category) {
        categoryMapper.insertSelective(category);
    }

    @Override
    public List<Category> selectCategorys() {
        //查找所以上架的类型对象
        CategoryExample categoryExample = new CategoryExample();
        CategoryExample.Criteria criteria = categoryExample.createCriteria();
        criteria.andStatedEqualTo(0);
        List<Category> list = categoryMapper.selectByExample(categoryExample);
        list = list.isEmpty()?null:list;
        return list;
    }

    @Override
    public List<Category> selectCategorys_All() {
        //查找所以上架的类型对象
        List<Category> list = categoryMapper.selectByExample(null);
        list = list.isEmpty()?null:list;
        return list;
    }

    @Override
    public String updateByCid(Category record) {
        //同Cid来更新类型对象
        int result = categoryMapper.updateByPrimaryKeySelective(record);
        if(result>0){
            return "YES";
        }
        return "NO";
    }

    @Override
    public String deleteByPrimaryKey(Integer cid) {
        //通过Cid来删除对象
        int result = categoryMapper.deleteByPrimaryKey(cid);
        if (result>0){
            return "YES";
        }
        return "NO";
    }


}
